<div class="layui-fluid layui-anim febs-anim" id="febs-teacherProject" lay-title="课程项目">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">

                    <form class="layui-form layui-table-form" lay-filter="teacherProject-table-form">
                        <div class="layui-row">

                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">班级：</label>
                                            <div class="layui-input-block">
                                                <select name="deptId" id="deptID" lay-verify="">
                                                    <option value="">请选择一个班级</option>
                                                    <div th:each="dept : ${depts}">
                                                        <option th:value=${dept.deptId}><span
                                                                th:text=${dept.deptName}></span></option>
                                                    </div>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query"
                                     onclick="query()">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="teacherProject:view">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>

                    <table lay-filter="teacherProjectTable_table" lay-data="{id: 'teacherProjectTable'}"></table>

                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="user-option">
    <span shiro:lacksPermission="teacherProject:view,teacherProject:update,teacherProject:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <!--<a lay-event="detail" shiro:hasPermission="teacherProject:view"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>-->
    <!--<a lay-event="edit" shiro:hasPermission="teacherProject:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>-->
    <a lay-event="del" shiro:hasPermission="teacherProject:delete"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#febs-teacherProject'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            selectValue,
            tableIns;
        form.render();
        initTable();

        //查询按钮的点击方法
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        function getQueryParams() {
            return {
                deptId: $("#deptID").val(),
            };
        }

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'teacherProjectTable_table',
                url: ctx + 'teacherScore/scoreList',
                cols: [[
                    {type: 'checkbox'},
                    //{field: 'teacherProjectId', title: '项目编号', minWidth: 100},
                    {field: 'idNumber', title: '学号', minWidth: 100},
                    {field: 'stuName', title: '学生姓名', minWidth: 100},
                    {field: 'deptName', title: '班级名称',minWidth: 100},
                    {field: 'courseName', title: '课程名称', minWidth: 100},
                    {field: 'projectName', title: '项目名称', minWidth: 100},
                    {field: 'teacherName', title: '老师名称', minWidth: 100},
                    {field: 'teacherName', title: '老师名称', minWidth: 100},
                    {field: 'reportUrl', title: '实验报告', minWidth: 100,
                        templet: function (d) {
                            return '<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="report">实验报告</button>';
                        }
                    },
                    {field: 'createTime', title: '上传时间', minWidth: 100,
                        templet: function(d){
                            if(d.createTime!=null){
                                return layui.util.toDateString(d.createTime);
                            }
                            return '';
                        }
                    },
                    {field: 'score', title: '成绩(双击编辑)',edit:true, minWidth: 100}
                   /* {title: '操作', toolbar: '#user-option', minWidth: 140}*/
                ]]
            })
        }

        dropdown.render({
            elem: $view.find('.action-more'),

            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('teacherProjectTable_table');
                if (name === 'add') {
                    febs.modal.open('添加实验项目', 'system/teacher/teacherProject/add', {
                        btn: ['提交', '重置'],
                        area: ["50%", "80%"],
                        yes: function (index, layero) {
                            $('#add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的实验项目');
                    } else {
                        febs.modal.confirm('删除实验项目', '确定删除该实验项目？', function () {
                            var userIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                userIds.push(item.teacherProjectId)
                            });
                            deleteTeacherProject(userIds.join(','));
                        });
                    }
                }
            },

            options: [{
                name: 'add',
                title: '新增项目',
                perms: 'experimentProject:add'
            }, {
                name: 'delete',
                title: '删除项目',
                perms: 'experimentProject:delete'
            }]
        });
        table.on('tool(teacherProjectTable_table)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除实验项目', '确定删除该实验项目？', function () {
                    deleteTeacherProject(data.teacherProjectId);
                });
            }
            if (layEvent === 'report') {
                window.location.href = ctx+"experimentProject/downloadFile?objectName="+data.reportUrl;
            }
        });

        table.on('edit(teacherProjectTable_table)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            // console.log(obj.value); //得到修改后的值
            // console.log(obj.field); //当前编辑的字段名
            // console.log(obj.data); //所在行的所有相关数据
            obj.data.createTime = null;
            febs.post(ctx + 'teacherScore/updateScore', obj.data, function () {
                febs.alert.success('修改成绩成功！');
            });
        });

        function deleteTeacherProject(teacherProjectId) {
            febs.get(ctx + 'teacherProject/delete/' + teacherProjectId, null, function () {
                febs.alert.success('删除课程成功');
                $query.click();
            });
        }
    })
</script>






